package io.renren.modules.ledger.controller;

import java.util.*;
import io.renren.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.modules.ledger.entity.MemberConnEntity;
import io.renren.modules.ledger.service.MemberConnService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import com.alibaba.fastjson.JSON;


/**
 * 用户关系表
 * @Author lililiang
 * @Date 2021-01-13 12:02:05
 */
@RestController
@Api(tags = "用户关系表")
@RequestMapping("/ledger/memberconn")
public class MemberConnController extends AbstractController{
    @Autowired
    private MemberConnService memberConnService;

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询", response = MemberConnEntity.class)
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils pageInfo = memberConnService.list4Page(params);
        return R.ok().put("page", pageInfo);
    }

    /**
     * 列表查询
     */
    @ApiOperation(value = "列表查询", response = MemberConnEntity.class)
    @GetMapping("/listByCondition")
    public R listByCondition(@RequestParam Map<String, Object> params){
        List<MemberConnEntity> list = memberConnService.listByCondition(params);
        return R.ok().put("list", list);
    }

    /**
     * 查询详情
     */
    @ApiOperation(value = "查询详情", response = MemberConnEntity.class)
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        MemberConnEntity memberConn = memberConnService.queryOneById(id);
        return R.ok().put("memberConn", memberConn);
    }

    /**
     * 新增保存
     */
    @ApiOperation(value = "新增保存", response = R.class)
    @PostMapping("/save")
    public R save(@RequestBody MemberConnEntity entity){
        return memberConnService.addConn(entity);
    }

    /**
     * 修改保存
     */
    @ApiOperation(value = "修改保存", response = R.class)
    @PostMapping("/update")
    public R update(@RequestBody MemberConnEntity entity){
		memberConnService.updateById(entity);
        return R.ok();
    }

    /**
     * 批量逻辑删除
     */
    @ApiOperation(value = "批量逻辑删除", response = R.class)
    @PostMapping("/delete")
    public R delete(@ApiParam(value = "Id数组， 例如 [1,2,3]", required = true) @RequestBody(required = true) String psIds){
		memberConnService.deleteLogic(JSON.parseArray(psIds, String.class));
        return R.ok();
    }

    /**
     * 同步数据
     */
    @ApiOperation(value = "同步数据", response = R.class)
    @PostMapping("/sync")
    public R sync(@RequestBody MemberConnEntity entity){
        return memberConnService.sync(entity);
    }

}
